```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring Boot与JPA集成指南 | 技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            line-height: 1.8;
            color: #333;
        }
        .serif {
            font-family: 'Noto Serif SC', serif;
        }
        .hero-bg {
            background: linear-gradient(135deg, #4f8bf9 0%, #2e60d4 100%);
        }
        .code-block {
            background-color: #f8f9fa;
            border-left: 4px solid #4f8bf9;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .transition-all {
            transition: all 0.3s ease;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-bg text-white py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-4xl mx-auto text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6 serif">Spring Boot与JPA集成完全指南</h1>
            <p class="text-xl md:text-2xl opacity-90 mb-8">掌握对象关系映射的艺术，构建高效持久层</p>
            <div class="flex justify-center space-x-4">
                <a href="#start" class="bg-white text-blue-600 hover:bg-blue-50 px-6 py-3 rounded-lg font-medium transition-all">
                    <i class="fas fa-rocket mr-2"></i>快速开始
                </a>
                <a href="#best-practices" class="border-2 border-white text-white hover:bg-white hover:text-blue-600 px-6 py-3 rounded-lg font-medium transition-all">
                    <i class="fas fa-star mr-2"></i>最佳实践
                </a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <!-- Introduction -->
        <section id="introduction" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center mr-4">
                    <i class="fas fa-play text-blue-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800 serif">引言</h2>
            </div>
            <div class="prose max-w-none text-gray-700">
                <p>Java Persistence API（JPA）是一个标准的对象关系映射（ORM）规范，它简化了Java对象与关系型数据库之间的映射和交互。Spring Boot与JPA的结合为开发者提供了一个强大的工具集，使得在项目中处理数据持久化变得更加便捷和高效。</p>
            </div>
        </section>

        <!-- Configuration -->
        <section id="start" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center mr-4">
                    <i class="fas fa-cog text-blue-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800 serif">Spring Boot与JPA的集成配置</h2>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <!-- Dependencies -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-blue-50 flex items-center justify-center mr-3">
                                <i class="fas fa-box-open text-blue-500"></i>
                            </div>
                            <h3 class="text-xl font-semibold text-gray-800">引入依赖</h3>
                        </div>
                        <p class="text-gray-600 mb-4">在Spring Boot项目中使用JPA，首先需要在项目的<code>pom.xml</code>文件中引入相关的依赖：</p>
                        <div class="code-block p-4 rounded-lg mb-4 overflow-x-auto">
                            <pre class="text-sm"><code>&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;com.h2database&lt;/groupId&gt;
    &lt;artifactId&gt;h2&lt;/artifactId&gt;
    &lt;scope&gt;runtime&lt;/scope&gt;
&lt;/dependency&gt;</code></pre>
                        </div>
                        <p class="text-gray-600">对于生产环境，通常会使用如MySQL或PostgreSQL等数据库，相应地需要调整依赖。</p>
                    </div>
                </div>

                <!-- Properties -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-blue-50 flex items-center justify-center mr-3">
                                <i class="fas fa-sliders-h text-blue-500"></i>
                            </div>
                            <h3 class="text-xl font-semibold text-gray-800">配置数据源和JPA属性</h3>
                        </div>
                        <p class="text-gray-600 mb-4">在<code>application.properties</code>或<code>application.yml</code>文件中配置数据源信息和JPA相关属性：</p>
                        <div class="code-block p-4 rounded-lg mb-4 overflow-x-auto">
                            <pre class="text-sm"><code>spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect</code></pre>
                        </div>
                        <p class="text-gray-600">这里的<code>spring.jpa.hibernate.ddl-auto</code>属性用于控制Hibernate的DDL操作模式。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Entity Mapping -->
        <section id="best-practices" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center mr-4">
                    <i class="fas fa-database text-blue-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800 serif">实体映射的最佳实践</h2>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <!-- Basic Entity -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-blue-50 flex items-center justify-center mr-3">
                                <i class="fas fa-table text-blue-500"></i>
                            </div>
                            <h3 class="text-xl font-semibold text-gray-800">定义实体类</h3>
                        </div>
                        <p class="text-gray-600 mb-4">实体类是JPA中映射到数据库表的核心。定义实体类时，需要使用<code>@Entity</code>注解标记，并指定主键：</p>
                        <div class="code-block p-4 rounded-lg overflow-x-auto">
                            <pre class="text-sm"><code>@Entity
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String name;
    private String email;
    // getters and setters
}</code></pre>
                        </div>
                    </div>
                </div>

                <!-- Relationship Diagram -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-blue-50 flex items-center justify-center mr-3">
                                <i class="fas fa-project-diagram text-blue-500"></i>
                            </div>
                            <h3 class="text-xl font-semibold text-gray-800">关联映射关系</h3>
                        </div>
                        <div class="mermaid">
                            erDiagram
                                USER ||--o{ ADDRESS : has
                                DEPARTMENT ||--o{ EMPLOYEE : contains
                        </div>
                    </div>
                </div>
            </div>

            <!-- Relationship Examples -->
            <div class="grid md:grid-cols-2 gap-8">
                <!-- One-to-One -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all card-hover">
                    <div class="p-6">
                        <h3 class="text-lg font-semibold text-gray-800 mb-4">一对一映射</h3>
                        <div class="code-block p-4 rounded-lg overflow-x-auto">
                            <pre class="text-sm"><code>@Entity
public class Address {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String street;
    @OneToOne(mappedBy = "address")
    private User user;
}

@Entity
public class User {
    //...
    @OneToOne
    @JoinColumn(name = "address_id")
    private Address address;
}</code></pre>
                        </div>
                    </div>
                </div>

                <!-- One-to-Many -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all card-hover">
                    <div class="p-6">
                        <h3 class="text-lg font-semibold text-gray-800 mb-4">一对多映射</h3>
                        <div class="code-block p-4 rounded-lg overflow-x-auto">
                            <pre class="text-sm"><code>@Entity
public class Department {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String name;
    @OneToMany(mappedBy = "department")
    private List&lt;Employee&gt; employees;
}

@Entity
public class Employee {
    //...
    @ManyToOne
    @JoinColumn(name = "department_id")
    private Department department;
}</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Query Optimization -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center mr-4">
                    <i class="fas fa-search text-blue-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800 serif">查询优化的策略</h2>
            </div>

            <div class="grid md:grid-cols-3 gap-6 mb-8">
                <!-- JPQL -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-blue-50 flex items-center justify-center mr-3">
                                <i class="fas fa-language text-blue-500"></i>
                            </div>
                            <h3 class="text-xl font-semibold text-gray-800">JPQL查询</h3>
                        </div>
                        <p class="text-gray-600 mb-4">JPA提供了JPQL用于执行面向对象的查询：</p>
                        <div class="code-block p-4 rounded-lg overflow-x-auto">
                            <pre class="text-sm"><code>@Repository
public interface UserRepository extends JpaRepository&lt;User, Long&gt; {
    @Query("SELECT u FROM User u WHERE u.name = :name")
    List&lt;User&gt; findByName(@Param("name") String name);
}</code></pre>
                        </div>
                    </div>
                </div>

                <!-- Native SQL -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-blue-50 flex items-center justify-center mr-3">
                                <i class="fas fa-database text-blue-500"></i>
                            </div>
                            <h3 class="text-xl font-semibold text-gray-800">原生SQL</h3>
                        </div>
                        <p class="text-gray-600 mb-4">在性能敏感的场景下，可以使用原生SQL：</p>
                        <div class="code-block p-4 rounded-lg overflow-x-auto">
                            <pre class="text-sm"><code>@Query(value = "SELECT * FROM user WHERE name = :name", 
       nativeQuery = true)
List&lt;User&gt; findByNameNative(@Param("name") String name);</code></pre>
                        </div>
                    </div>
                </div>

                <!-- Projection -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-blue-50 flex items-center justify-center mr-3">
                                <i class="fas fa-filter text-blue-500"></i>
                            </div>
                            <h3 class="text-xl font-semibold text-gray-800">投影查询</h3>
                        </div>
                        <p class="text-gray-600 mb-4">当只需要部分字段时，可以使用投影查询减少数据加载：</p>
                        <div class="code-block p-4 rounded-lg overflow-x-auto">
                            <pre class="text-sm"><code>public interface UserProjection {
    String getName();
    String getEmail();
}

@Repository
public interface UserRepository extends JpaRepository&lt;User, Long&gt; {
    List&lt;UserProjection&gt; findByActiveTrue();
}</code></pre>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Caching -->
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 transition-all card-hover">
                <div class="p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 rounded-full bg-blue-50 flex items-center justify-center mr-3">
                            <i class="fas fa-bolt text-blue-500"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">缓存的使用</h3>
                    </div>
                    <p class="text-gray-600 mb-4">JPA支持一级缓存和二级缓存。二级缓存可以显著提高查询性能：</p>
                    <div class="grid md:grid-cols-2 gap-6">
                        <div>
                            <div class="code-block p-4 rounded-lg overflow-x-auto">
                                <pre class="text-sm"><code>&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-cache&lt;/artifactId&gt;
&lt;/dependency&gt;</code></pre>
                            </div>
                        </div>
                        <div>
                            <div class="code-block p-4 rounded-lg overflow-x-auto">
                                <pre class="text-sm"><code>@Configuration
@EnableCaching
public class CacheConfig {
    @Bean
    public JCacheManagerCustomizer jCacheManagerCustomizer() {
        return cacheManager -&gt; cacheManager.createCache("users", 
            JCacheConfigurationBuilder.newBuilder()
                .expireAfterWrite(10, TimeUnit.MINUTES)
                .maximumSize(100)
                .build()
        );
    }
}</code></pre>
                            </div>
                        </div>
                    </div>
                    <p class="text-gray-600 mt-4">在实体类上使用<code>@Cacheable</code>注解标记可以被缓存的实体。</p>
                </div>
            </div>
        </section>

        <!-- Transaction Management -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center mr-4">
                    <i class="fas fa-exchange-alt text-blue-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800 serif">事务管理的要点</h2>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <!-- Declarative -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-blue-50 flex items-center justify-center mr-3">
                                <i class="fas fa-code text-blue-500"></i>
                            </div>
                            <h3 class="text-xl font-semibold text-gray-800">声明式事务管理</h3>
                        </div>
                        <p class="text-gray-600 mb-4">使用<code>@Transactional</code>注解可以方便地为方法或类添加事务支持：</p>
                        <div class="code-block p-4 rounded-lg overflow-x-auto">
                            <pre class="text-sm"><code>@Service
public class UserService {
    @Autowired
    private UserRepository userRepository;

    @Transactional
    public void createUser(User user) {
        userRepository.save(user);
        // other operations
    }
}</code></pre>
                        </div>
                    </div>
                </div>

                <!-- Propagation -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-blue-50 flex items-center justify-center mr-3">
                                <i class="fas fa-random text-blue-500"></i>
                            </div>
                            <h3 class="text-xl font-semibold text-gray-800">事务传播机制</h3>
                        </div>
                        <p class="text-gray-600 mb-4">常见的事务传播机制有：</p>
                        <ul class="list-disc pl-5 text-gray-600 space-y-2">
                            <li><code>REQUIRED</code>（默认）：如果当前存在事务，则加入该事务；否则创建一个新的事务。</li>
                            <li><code>REQUIRES_NEW</code>：无论当前是否存在事务，都创建一个新的事务。</li>
                            <li><code>NESTED</code>：如果当前存在事务，则在嵌套事务中执行；否则创建一个新的事务。</li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- Performance Monitoring -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center mr-4">
                    <i class="fas fa-tachometer-alt text-blue-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800 serif">性能监控与调试</h2>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <!-- Hibernate Stats -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-blue-50 flex items-center justify-center mr-3">
                                <i class="fas fa-chart-bar text-blue-500"></i>
                            </div>
                            <h3 class="text-xl font-semibold text-gray-800">Hibernate Statistics</h3>
                        </div>
                        <p class="text-gray-600 mb-4">启用Hibernate的统计功能监控JPA运行性能：</p>
                        <div class="code-block p-4 rounded-lg overflow-x-auto">
                            <pre class="text-sm"><code>spring.jpa.properties.hibernate.generate_statistics=true</code></pre>
                        </div>
                        <div class="code-block p-4 rounded-lg overflow-x-auto mt-4">
                            <pre class="text-sm"><code>@Autowired
private EntityManagerFactory entityManagerFactory;

public void printStatistics() {
    Statistics statistics = entityManagerFactory
        .unwrap(SessionFactory.class)
        .getStatistics();
    System.out.println("Query Execution Count: " + 
        statistics.getQueryExecutionCount());
    // other statistics
}</code></pre>
                        </div>
                    </div>
                </div>

                <!-- Slow Query -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-blue-50 flex items-center justify-center mr-3">
                                <i class="fas fa-clock text-blue-500"></i>
                            </div>
                            <h3 class="text-xl font-semibold text-gray-800">慢查询日志</h3>
                        </div>
                        <p class="text-gray-600 mb-4">配置数据库的慢查询日志可以发现性能瓶颈。对于MySQL：</p>
                        <div class="code-block p-4 rounded-lg overflow-x-auto">
                            <pre class="text-sm"><code>spring.datasource.hikari.connection-init-sql=SET GLOBAL slow_query_log = 'ON';
spring.datasource.hikari.connection-init-sql=SET GLOBAL long_query_time = 1;</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-8">
        <div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex flex-col items-center">
                <div class="text-xl font-bold mb-2">技术小馆</div>
                <div class="text-gray-400 mb-4">
                    <a href="http://www.yuque.com/jtostring" class="hover:text-white transition-colors">
                        <i class="fas fa-link mr-1"></i> www.yuque.com/jtostring
                    </a>
                </div>
                <div class="text-gray-500 text-sm">© 2023 技术小馆. All rights reserved.</div>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            er: {
                diagramPadding: 10,
                layoutDirection: 'TB',
                useMaxWidth: true,
                fontSize: 14
            }
        });
    </script>
</body>
</html>
```